package com.classic.common.simple;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 应用名称: MultipleStatusView
 * 包 名 称: com.classic.common.simple
 * <p>
 * 创 建 人: 续写经典
 * 创建时间: 2017/7/7 15:51
 */
final class Utils {
    private static final AtomicInteger NEXT_GENERATED_ID = new AtomicInteger(1);

    static int generateViewId() {
        for (; ; ) {
            final int result = NEXT_GENERATED_ID.get();
            int newValue = result + 1;
            if (newValue > 0x00FFFFFF) {
                newValue = 1; // Roll over to 1, not 0.
            }
            if (NEXT_GENERATED_ID.compareAndSet(result, newValue)) {
                return result;
            }
        }
    }
}
